package com.stylefeng.guns.modular.vpn.utils;

import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;

import java.util.List;
import java.util.Map;

/**
 * @Description TODO
 * @Author Mr.God
 * @Date 2020-03-11 11:08
 **/
public class ExportFileUtil {
    /**
     * 拉新用户
     * @param maps
     * @param sheet
     */
    public static void exportNewUserInfo(List<Map<String,Object>> maps, HSSFSheet sheet){
        //新增数据行，并且设置单元格数据
        if(maps != null){
            int len = maps.size();
            for (int i = 0;i<len;i++){
                HSSFRow row = sheet.createRow(i+1);
                Map<String,Object> infoMap = maps.get(i);
                row.createCell(0).setCellValue(""+infoMap.get("createTime"));
                row.createCell(1).setCellValue(""+infoMap.get("todayDownloadCount"));
                row.createCell(2).setCellValue(""+infoMap.get("totalDownloadCount"));
                row.createCell(3).setCellValue(""+infoMap.get("todayRegCount"));
                row.createCell(4).setCellValue(""+infoMap.get("totalRegCount"));
                row.createCell(5).setCellValue(""+infoMap.get("paymentCount"));
                row.createCell(6).setCellValue(""+infoMap.get("iosCount"));
                row.createCell(7).setCellValue(""+infoMap.get("androidCount"));
                row.createCell(8).setCellValue(""+infoMap.get("pcCount"));
            }
        }
    }

    /**
     * 用户留存数据
     * @param maps
     * @param sheet
     */
    public static void exportRetentionUserInfo(List<Map<String,Object>> maps, HSSFSheet sheet){
        //新增数据行，并且设置单元格数据
        if(maps != null){
            int len = maps.size();
            for (int i = 0;i<len;i++){
                HSSFRow row = sheet.createRow(i+1);
                Map<String,Object> infoMap = maps.get(i);
                row.createCell(0).setCellValue(""+infoMap.get("createTime"));
                row.createCell(1).setCellValue(""+infoMap.get("manyDeviceOnlineCount"));
                row.createCell(2).setCellValue(""+infoMap.get("totalOnlineUserCount"));
                row.createCell(3).setCellValue(""+infoMap.get("onlineTotalCount"));
                row.createCell(4).setCellValue(""+infoMap.get("accountAverageOnlineTime"));
                row.createCell(5).setCellValue(""+infoMap.get("deviceAverageOnlineTime"));
            }
        }
    }

    /**
     * 财务数据
     * @param maps
     * @param sheet
     */
    public static void exportFinancialInfo(List<Map<String,Object>> maps, HSSFSheet sheet){
        //新增数据行，并且设置单元格数据
        if(maps != null){
            int len = maps.size();
            for (int i = 0;i<len;i++){
                HSSFRow row = sheet.createRow(i+1);
                Map<String,Object> infoMap = maps.get(i);
                row.createCell(0).setCellValue(""+infoMap.get("createTime"));
                row.createCell(1).setCellValue(""+infoMap.get("todayMemberCount"));
                row.createCell(2).setCellValue(""+infoMap.get("todayTotalAmount"));
                row.createCell(3).setCellValue(""+infoMap.get("todayNonPaymentCount"));
                row.createCell(4).setCellValue(""+infoMap.get("todayBuyP0Count"));
                row.createCell(5).setCellValue(""+infoMap.get("todayBuyP1Count"));
                row.createCell(6).setCellValue(""+infoMap.get("todayBuyP2Count"));
                row.createCell(7).setCellValue(""+infoMap.get("todayBuyP3Count"));

                row.createCell(8).setCellValue(""+infoMap.get("todayBuyP4Count"));
                row.createCell(9).setCellValue(""+infoMap.get("buyP0TotalCount"));
                row.createCell(10).setCellValue(""+infoMap.get("buyP1TotalCount"));
                row.createCell(11).setCellValue(""+infoMap.get("buyP2TotalCount"));
                row.createCell(12).setCellValue(""+infoMap.get("buyP3TotalCount"));
                row.createCell(13).setCellValue(""+infoMap.get("buyP4TotalCount"));
                row.createCell(14).setCellValue(""+infoMap.get("totalNonPaymentCount"));
                row.createCell(15).setCellValue(""+infoMap.get("totalPaymentRatio"));
            }
        }
    }

    /**
     * 导出用户表信息
     * @param userInfoList
     * @param sheet
     */
    public  static void exportUserInfo(List<Map<String,Object>> userInfoList,HSSFSheet sheet){
        if(userInfoList != null){
            int len = userInfoList.size();

            for (int i = 0;i<len;i++){
                HSSFRow row = sheet.createRow(i+1);
                Map<String,Object> userInfo = userInfoList.get(i);
                row.createCell(0).setCellValue(""+userInfo.get("userName"));
                row.createCell(1).setCellValue(""+userInfo.get("ipAddr"));
                String platform = "";
                if(userInfo.get("curPlatform") != null){
                    Integer cp = (Integer) userInfo.get("curPlatform");
                    if(1 == cp){
                        platform =  "安卓";
                    }
                    else if(2 == cp){
                        platform = "IOS";
                    }
                    else if(3 == cp){
                        platform = "Windows";
                    }
                    else if(4 == cp){
                        platform = "Mac";
                    }
                    else if(5 == cp){
                        platform = "H5";
                    }
                }

                row.createCell(2).setCellValue(platform);

                row.createCell(3).setCellValue(""+userInfo.get("regVersion"));
                row.createCell(4).setCellValue(""+userInfo.get("regTime"));
                row.createCell(5).setCellValue(""+userInfo.get("lastOnlineTime"));
                String payWay = "";
                if(userInfo.get("paymentWay") != null){
                    Integer pw = (Integer) userInfo.get("paymentWay");

                    if(1 == pw){
                        payWay = "支付宝";
                    }
                    else if(2 == pw){
                        payWay = "微信支付";
                    }
                    else if(3 == pw){
                        payWay = "银联";
                    }
                    else if(4 == pw){
                        payWay = "Visa";
                    }
                    else if(5 == pw){
                        payWay = "Master";
                    }
                    else if(6 == pw){
                        payWay = "IOS内购";
                    }
                    else if(7 == pw){
                        payWay = "GooglePay";
                    }
                }

                row.createCell(6).setCellValue(payWay);

                row.createCell(7).setCellValue(""+userInfo.get("paymentCount"));
                row.createCell(8).setCellValue(""+userInfo.get("packageName"));
                row.createCell(9).setCellValue(""+userInfo.get("beginTime"));
                row.createCell(10).setCellValue(""+userInfo.get("endTime"));
            }

        }
    }
}
